Skip to content

fix: respect 'always snap to grid' when auto-scale layout from nodes 1.0 to 2.0#9332

Merged
christian-byrne merged 9 commits intoComfy-Org:mainfrom
woct0rdho:snap-to-grid
Mar 13, 2026
Merged

fix: respect 'always snap to grid' when auto-scale layout from nodes 1.0 to 2.0#9332
christian-byrne merged 9 commits intoComfy-Org:mainfrom
woct0rdho:snap-to-grid

Conversation

@woct0rdho
Copy link
Contributor

@woct0rdho woct0rdho commented Mar 2, 2026

Summary

Previously when I switch from nodes 1.0 to 2.0, positions and sizes of nodes do not follow 'always snap to grid'. You can guess what a mess it is for people relying on snap to grid to retain sanity. This PR fixes it.

Changes

In ensureCorrectLayoutScale, we call snapPoint after the position and the size are updated.

We also need to ensure that the snapped size is larger than the minimal size required by the content, so I've added 'ceil' mode to snapPoint, and the patch is larger than I thought first.

I'd happily try out nodes 2.0 once this is addressed :)

┆Issue is synchronized with this Notion page by Unito

@woct0rdho woct0rdho requested a review from a team as a code owner March 2, 2026 06:53
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 2, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

A single file enhancement that introduces grid-snapping support to the layout scaling logic by centralizing settings store access, implementing a target-based calculation approach for positions and sizes, and applying conditional snapping across all affected UI elements.

Changes

Cohort / File(s) Summary
Grid-Snapping Layout Enhancement
src/renderer/extensions/vueNodes/layout/ensureCorrectLayoutScale.ts
Centralized settings store access, added grid-snapping helper with fallback to LiteGraph.CANVAS_GRID_SIZE, refactored position and size calculations to use target-based approach with conditional snapping applied to nodes, reroutes, I/O nodes, and groups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The grid whispers softly, "snap here, snap there,"
As layouts dance with newfound care,
With target positions precisely aligned,
And snapping logic so well-designed,
The canvas sings in harmonious grace! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing the 'always snap to grid' behavior during node layout auto-scaling from version 1.0 to 2.0.
Description check ✅ Passed The PR description adequately explains the problem, solution, and implementation details with clear examples of what was changed and why.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure the reviews.tools.github-checks setting to adjust the time to wait for GitHub Checks to complete.

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

🎨 Storybook: loading Building...

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

🎭 Playwright: ⏳ Running...

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/extensions/vueNodes/layout/ensureCorrectLayoutScale.ts (1)

61-65: Consider using a function declaration instead of an arrow function.

Per coding guidelines, function declarations are preferred over expressions when possible.

♻️ Suggested refactor
-  const applySnap = (pos: [number, number]) => {
+  function applySnap(pos: [number, number]) {
     if (alwaysSnapToGrid) {
       snapPoint(pos, snapSize)
     }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/extensions/vueNodes/layout/ensureCorrectLayoutScale.ts` around
lines 61 - 65, Replace the arrow function expression "const applySnap = (pos:
[number, number]) => { if (alwaysSnapToGrid) { snapPoint(pos, snapSize) } }"
with a function declaration "function applySnap(pos: [number, number]) { if
(alwaysSnapToGrid) { snapPoint(pos, snapSize) } }" so it follows the project
guideline preferring declarations; keep the same parameter type and body, and
ensure any usages of applySnap continue to work (no change to call sites or
captured variables like alwaysSnapToGrid and snapSize).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/extensions/vueNodes/layout/ensureCorrectLayoutScale.ts`:
- Around line 61-65: Replace the arrow function expression "const applySnap =
(pos: [number, number]) => { if (alwaysSnapToGrid) { snapPoint(pos, snapSize) }
}" with a function declaration "function applySnap(pos: [number, number]) { if
(alwaysSnapToGrid) { snapPoint(pos, snapSize) } }" so it follows the project
guideline preferring declarations; keep the same parameter type and body, and
ensure any usages of applySnap continue to work (no change to call sites or
captured variables like alwaysSnapToGrid and snapSize).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84d7aa0 and 1272a08.

📒 Files selected for processing (1)
  • src/renderer/extensions/vueNodes/layout/ensureCorrectLayoutScale.ts

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 11, 2026
@woct0rdho woct0rdho closed this Mar 11, 2026
@woct0rdho woct0rdho reopened this Mar 11, 2026
@christian-byrne christian-byrne self-assigned this Mar 12, 2026
@woct0rdho
Copy link
Contributor Author

Hi @christian-byrne , thank you for the review! I've implemented the requested changes.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Mar 13, 2026
@woct0rdho
Copy link
Contributor Author

I've merged the main branch with #9680 which changed ensureCorrectLayoutScale a lot. Please check again.

Copy link
Contributor

@christian-byrne christian-byrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All review feedback addressed. Clean, focused change - snap-to-grid logic is additive with safe defaults, good test coverage for new ceil/floor modes.

Copy link
Contributor

@christian-byrne christian-byrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@christian-byrne christian-byrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked after the merge with #9680. The refactored ensureCorrectLayoutScale merged cleanly - snap logic (applySnap helper, unprojectPosSize with graph param, ceil for sizes) is correctly layered on the new simplified structure. Typecheck passes.

@christian-byrne christian-byrne merged commit 82556f0 into Comfy-Org:main Mar 13, 2026
40 checks passed
@woct0rdho woct0rdho deleted the snap-to-grid branch March 13, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants